package top.kindaries;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import top.kindaries.device.DeviceManager;
import top.kindaries.device.provider.IDeviceProvider;
import top.kindaries.utils.PropUtil;

/**
 * @ClassName: ServeApplication
 * @Description: 微服务启动类
 * Author: zhangs
 * Date: Created in 2021-09-20 9:48
 * Created by IntelliJ IDEA.
 */
@SpringBootApplication
public class ServeApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServeApplication.class, args);
        // 设置监控设备管理器
        PropUtil.use("config/config.properties");
        // 默认加载方式[top.kindaries.device.provider.impl.DefaultProvider]
        if (PropUtil.containsKey("device.provider")) {
            String deviceProviderClass = PropUtil.get("device.provider");
            try {
                Class clazz = Class.forName(deviceProviderClass);
                Object instance = clazz.newInstance();
                if (instance instanceof IDeviceProvider) {
                    DeviceManager.setProvider((IDeviceProvider) instance);
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("加载监控设备管理器失败，请检查配置");
            }
        }
    }

}
